package com.yao.guli.product.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yao.guli.product.entity.AttrGroupEntity;
import com.yao.guli.product.service.PmsAttrGroupService;
import com.yao.common.utils.PageUtils;
import com.yao.common.utils.R;



/**
 * 属性分组
 *
 * @author hzyao
 * @email 75476439@qq.com
 * @date 2020-08-22 22:15:14
 */
@RestController
@RequestMapping("product/attrgroup")
public class PmsAttrGroupController {
    @Autowired
    private PmsAttrGroupService pmsAttrGroupService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:pmsattrgroup:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = pmsAttrGroupService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list/{categoryId}")
    //@RequiresPermissions("product:attrgroup:list")
    public R list(@RequestParam Map<String, Object> params, @PathVariable("categoryId") Long categoryId){
        // params获取的参数是？后边拼接的参数，而categoryId是路径/带的，两者获取参数的方法不同
        // 请求的URL：http://localhost:8888/api/product/attrgroup/list/225?t=1598076577694&page=1&limit=10&key=
        // PageUtils page = attrGroupService.queryPage(params);

        // 新增接口方法（原来只传递分页参数，现在还需要带一个业务参数categoryId，所以，需要新封装接口方法）
        PageUtils page = pmsAttrGroupService.queryPage(params, categoryId);

        return R.ok().put("page", page);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("product:pmsattrgroup:info")
    public R info(@PathVariable("id") Long id){
		AttrGroupEntity pmsAttrGroup = pmsAttrGroupService.getById(id);

        return R.ok().put("pmsAttrGroup", pmsAttrGroup);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:pmsattrgroup:save")
    public R save(@RequestBody AttrGroupEntity pmsAttrGroup){
		pmsAttrGroupService.save(pmsAttrGroup);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:pmsattrgroup:update")
    public R update(@RequestBody AttrGroupEntity pmsAttrGroup){
		pmsAttrGroupService.updateById(pmsAttrGroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:pmsattrgroup:delete")
    public R delete(@RequestBody Long[] ids){
		pmsAttrGroupService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
